package muilt;

import java.io.IOException;
import java.util.List;
import java.util.Random;
import java.util.concurrent.CompletableFuture;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.junit.Test;

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.luculent.base.section.FPBSend;
import com.luculent.result.Response;
import com.luculent.utils.FPBTableUtils;
import com.luculent.utils.WorkId;

public class RunHttp {
	@Test
	public void test() throws Exception{
		List<CompletableFuture> a = Lists.newArrayList(); 
		for(int i=0;i<10;i++){ 
			a.add(CompletableFuture.runAsync(() -> {
				int ym = new Random().nextInt(100);
				HttpClient clientCode = getClient();
				String nHead = WorkId.sortUID();
				String imgUrl = "http://192.168.0.20:8082/cf_fpb/fupin/?iw-apikey=123&iw-cmd=workId&ym="+ym+"&requestId="+nHead;
				HttpGet siginPostCode = new HttpGet(imgUrl); 
				siginPostCode.setHeader("User-Agent",FPBSend.agent); 
				HttpResponse HtmlRespCode;
				try {
					HtmlRespCode = clientCode.execute(siginPostCode);
					System.out.println("当前页面为："+nHead+"=="+ym+"==返回结果为："+EntityUtils.toString(HtmlRespCode.getEntity(), "UTF-8")); 
				} catch (IOException e){ 
					e.printStackTrace();
				}    
				
			}));
		}
		CompletableFuture.allOf(a.toArray(new CompletableFuture[a.size()])).get();
	}
	
	
	public HttpClient getClient(){ 
		return  HttpClients.createDefault();
	}
	 
}
